package com.jch.helloworld.configBeans.spel;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestMain {

    public static void main(String[] args) {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("/beans/beans-spel.xml");
        System.out.println("SpEL表达式使用字面值：");
        Demo literal = (Demo) ctx.getBean("literal");
        System.out.println("literal = " + literal);
        System.out.println("SpEL表达式引用bean：");
        Home refBean = (Home) ctx.getBean("refBean");
        System.out.println("refBean = " + refBean);
        System.out.println("SpEL表达式引用其他bean的属性：");
        Demo refOtherBeanAttr = (Demo) ctx.getBean("refOtherBeanAttr");
        System.out.println("refOtherBeanAttr：" + refOtherBeanAttr);
        System.out.println("SpEL表达式的链式操作：");
        Home chainOper = (Home) ctx.getBean("chainOper");
        System.out.println("chainOper = " + chainOper);
        System.out.println("SpEL表达式的算术运算符：");
        Oper arithmetic = (Oper) ctx.getBean("arithmetic");
        System.out.println("arithmetic: " + arithmetic);
        System.out.println("SpEL表达式的字符串链接符：");
        Oper str = (Oper) ctx.getBean("str");
        System.out.println("str: " + str.getStr());
        System.out.println("SpEL表达式的比较运算符：");
        Compare compare = (Compare) ctx.getBean("compare");
        System.out.println("compare: " + compare);
        System.out.println("SpEL表达式的逻辑运算符：");
        Compare compare1 = (Compare) ctx.getBean("logical");
        System.out.println("logical: " + compare1);
        System.out.println("SpEL表达式的if-else运算符：");
        Home ifElse = (Home) ctx.getBean("ifElse");
        System.out.println("ifElse：" + ifElse);
        System.out.println("SpEL表达式的if-else运算符变体：");
        Home ifElse2 = (Home) ctx.getBean("ifElse2");
        System.out.println("ifElse2: " + ifElse2);
        System.out.println("SpEL表达式的正则表达式使用：");
        Home matches = (Home) ctx.getBean("matches1");
        System.out.println("matches: " + matches);
        System.out.println("SpEL表达式的调用静态方法：");
        Oper staticFunction = (Oper) ctx.getBean("staticFunction");
        System.out.println(staticFunction);
    }

}
